#
# Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=netcwmp
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/netcwmp
  SECTION:=Utils
  CATEGORY:=Utilities
  TITLE:= A CWMP client implement
  DEPENDS:=+libpthread +librt +libopenssl +libuci +libsuci
endef

define Package/netcwmp/description
 This package contains an daemon to act as tr069 client.
endef

define Package/netcwmp/config
  choice
    depends on PACKAGE_netcwmp
  endchoice

  config netcwmp_support_stun
    depends on PACKAGE_netcwmp
    bool "netcwmp support stun"
    default n

endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

CONFIGURE_ARGS+= \
	--disable-option-checking

#define Build/Configure
#	mkdir -p $(PKG_BUILD_DIR)/build
#	$(Build/Configure/Default)
#endef

#TARGET_CFLAGS += $(FPIC) -ffunction-sections -fdata-sections
#TARGET_CFLAGS += -D_GNU_SOURCE -DUSE_CWMP_MEMORY_POOL
TARGET_CPPFLAGS += -D_GNU_SOURCE -DUSE_CWMP_MEMORY_POOL
TARGET_LDFLAGS += -W
EXTENAL_CFLAGS += -lpthread -lrt -luci -lsuci
EXTRA_LDFLAGS += -Wl,-rpath-link,$(STAGING_DIR)/usr/lib

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		CC="$(TARGET_CC)"
		CPPFLAGS+="$(TARGET_CPPFLAGS) $(EXTENAL_CFLAGS)" \
		LDFLAGS+="$(TARGET_LDFLAGS) $(EXTENAL_CFLAGS)"
endef

define Build/InstallDev
endef

define Package/netcwmp/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/cwmpd/src/cwmpd $(1)/usr/sbin/netcwmpd
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_CONF) ./files/netcwmp.config $(1)/etc/config/netcwmp
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/netcwmp.init $(1)/etc/init.d/netcwmpd
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_CONF) ./src/conf/cwmp.conf $(1)/etc/cwmp.conf
	$(INSTALL_CONF) ./src/conf/device.xml $(1)/etc/device.xml
endef

$(eval $(call BuildPackage,netcwmp))
